1   /*                        __    __  __  __    __  ___
2    *                       \  \  /  /    \  \  /  /  __/
3    *                        \  \/  /  /\  \  \/  /  /
4    *                         \____/__/  \__\____/__/.ɪᴏ
5    * ᶜᵒᵖʸʳᶦᵍʰᵗ ᵇʸ ᵛᵃᵛʳ ⁻ ˡᶦᶜᵉⁿˢᵉᵈ ᵘⁿᵈᵉʳ ᵗʰᵉ ᵃᵖᵃᶜʰᵉ ˡᶦᶜᵉⁿˢᵉ ᵛᵉʳˢᶦᵒⁿ ᵗʷᵒ ᵈᵒᵗ ᶻᵉʳᵒ
6    */
7   package io.vavr.test;
8   
9   /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*\
10     G E N E R A T O R   C R A F T E D
11  \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
12  
13  import static org.assertj.core.api.Assertions.assertThat;
14  
15  import io.vavr.CheckedFunction8;
16  import org.junit.Test;
17  
18  public class PropertyCheck8Test {
19  
20      static final Arbitrary<Object> OBJECTS = Gen.of(null).arbitrary();
21  
22      @Test
23      public void shouldApplyForAllOfArity8() {
24          final Property.ForAll8<Object, Object, Object, Object, Object, Object, Object, Object> forAll = Property.def("test").forAll(null, null, null, null, null, null, null, null);
25          assertThat(forAll).isNotNull();
26      }
27  
28      @Test
29      public void shouldApplySuchThatOfArity8() {
30          final Property.ForAll8<Object, Object, Object, Object, Object, Object, Object, Object> forAll = Property.def("test").forAll(OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS);
31          final CheckedFunction8<Object, Object, Object, Object, Object, Object, Object, Object, Boolean> predicate = (o1, o2, o3, o4, o5, o6, o7, o8) -> true;
32          final Property.Property8<Object, Object, Object, Object, Object, Object, Object, Object> suchThat = forAll.suchThat(predicate);
33          assertThat(suchThat).isNotNull();
34      }
35  
36      @Test
37      public void shouldCheckTrueProperty8() {
38          final Property.ForAll8<Object, Object, Object, Object, Object, Object, Object, Object> forAll = Property.def("test").forAll(OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS);
39          final CheckedFunction8<Object, Object, Object, Object, Object, Object, Object, Object, Boolean> predicate = (o1, o2, o3, o4, o5, o6, o7, o8) -> true;
40          final CheckResult result = forAll.suchThat(predicate).check();
41          assertThat(result.isSatisfied()).isTrue();
42          assertThat(result.isExhausted()).isFalse();
43      }
44  
45      @Test
46      public void shouldCheckFalseProperty8() {
47          final Property.ForAll8<Object, Object, Object, Object, Object, Object, Object, Object> forAll = Property.def("test").forAll(OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS);
48          final CheckedFunction8<Object, Object, Object, Object, Object, Object, Object, Object, Boolean> predicate = (o1, o2, o3, o4, o5, o6, o7, o8) -> false;
49          final CheckResult result = forAll.suchThat(predicate).check();
50          assertThat(result.isFalsified()).isTrue();
51      }
52  
53      @Test
54      public void shouldCheckErroneousProperty8() {
55          final Property.ForAll8<Object, Object, Object, Object, Object, Object, Object, Object> forAll = Property.def("test").forAll(OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS);
56          final CheckedFunction8<Object, Object, Object, Object, Object, Object, Object, Object, Boolean> predicate = (o1, o2, o3, o4, o5, o6, o7, o8) -> { throw new RuntimeException("yay! (this is a negative test)"); };
57          final CheckResult result = forAll.suchThat(predicate).check();
58          assertThat(result.isErroneous()).isTrue();
59      }
60  
61      @Test
62      public void shouldCheckProperty8ImplicationWithTruePrecondition() {
63          final Property.ForAll8<Object, Object, Object, Object, Object, Object, Object, Object> forAll = Property.def("test").forAll(OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS);
64          final CheckedFunction8<Object, Object, Object, Object, Object, Object, Object, Object, Boolean> p1 = (o1, o2, o3, o4, o5, o6, o7, o8) -> true;
65          final CheckedFunction8<Object, Object, Object, Object, Object, Object, Object, Object, Boolean> p2 = (o1, o2, o3, o4, o5, o6, o7, o8) -> true;
66          final CheckResult result = forAll.suchThat(p1).implies(p2).check();
67          assertThat(result.isSatisfied()).isTrue();
68          assertThat(result.isExhausted()).isFalse();
69      }
70  
71      @Test
72      public void shouldCheckProperty8ImplicationWithFalsePrecondition() {
73          final Property.ForAll8<Object, Object, Object, Object, Object, Object, Object, Object> forAll = Property.def("test").forAll(OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS);
74          final CheckedFunction8<Object, Object, Object, Object, Object, Object, Object, Object, Boolean> p1 = (o1, o2, o3, o4, o5, o6, o7, o8) -> false;
75          final CheckedFunction8<Object, Object, Object, Object, Object, Object, Object, Object, Boolean> p2 = (o1, o2, o3, o4, o5, o6, o7, o8) -> true;
76          final CheckResult result = forAll.suchThat(p1).implies(p2).check();
77          assertThat(result.isSatisfied()).isTrue();
78          assertThat(result.isExhausted()).isTrue();
79      }
80  
81      @Test(expected = IllegalArgumentException.class)
82      public void shouldThrowOnProperty8CheckGivenNegativeTries() {
83          Property.def("test")
84              .forAll(OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS)
85              .suchThat((o1, o2, o3, o4, o5, o6, o7, o8) -> true)
86              .check(Checkable.RNG.get(), 0, -1);
87      }
88  
89      @Test
90      public void shouldReturnErroneousProperty8CheckResultIfGenFails() {
91          final Arbitrary<Object> failingGen = Gen.fail("yay! (this is a negative test)").arbitrary();
92          final CheckResult result = Property.def("test")
93              .forAll(failingGen, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS)
94              .suchThat((o1, o2, o3, o4, o5, o6, o7, o8) -> true)
95              .check();
96          assertThat(result.isErroneous()).isTrue();
97      }
98  
99      @Test
100     public void shouldReturnErroneousProperty8CheckResultIfArbitraryFails() {
101         final Arbitrary<Object> failingArbitrary = size -> { throw new RuntimeException("yay! (this is a negative test)"); };
102         final CheckResult result = Property.def("test")
103             .forAll(failingArbitrary, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS, OBJECTS)
104             .suchThat((o1, o2, o3, o4, o5, o6, o7, o8) -> true)
105             .check();
106         assertThat(result.isErroneous()).isTrue();
107     }
108 }